<link rel="stylesheet" href="${request.contextPath}/static/oms/default/plugins/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<div class="row">
	<div class="col-md-12">
		<form id="userAddForm" action="${request.contextPath}/system/authority/user/save" method="post" onsubmit="return false">
			<div class="modal-body" >
				<div class="form-group">
					<label id="userNicknameLabel">昵称</label>
					<input type="text" class="form-control" name="nickname" id="userNickname" placeholder="输入昵称...">
				</div>
				<div class="form-group">
					<label id="userLoginnameLabel">登录名</label>
					<input type="text" class="form-control" name="loginname" id="userLoginname" placeholder="输入登录名...">
				</div>
				<div class="form-group">
					<label id="userPasswordLabel">登录密码</label>
					<input type="text" class="form-control" name="password" id="userPassword" placeholder="输入登录密码...">
				</div>
				<div class="form-group">
					<label id="userSignatureLabel">个性签名</label>
					<input type="text" class="form-control" name="signature" id="userSignature" placeholder="输入个性签名...">
				</div>
				<div class="form-group">
					<label id="userRemarkLabel">备注</label>
					<input type="text" class="form-control" name="remark" id="userRemark" placeholder="输入备注...">
				</div>
				<div class="error-message text-center" id="userAddFormErrorMsgContainer">
					<span class="error-icon"></span>
					<span id="userAddFormErrorMsg" class="error-msg" ></span>
				</div>
			</div>
			<div class="modal-footer">
				<div class="pull-right">
					<button type="submit" class="btn btn-primary btn-sm" ><i class="fa fa-save"></i> 保存</button>
					<button type="button" class="btn btn-default btn-sm" data-dismiss="modal"><i class="fa fa-close"></i> 取消</button>
				</div>
			</div>
		</form>
	</div>
</div>
<script type="text/javascript" src="${request.contextPath}/static/oms/default/plugins/zTree/jquery.ztree.all.js"></script>

<script type="text/javascript">
function ajaxSubmit(form) {
	
	var $form = $(form);
	
	if ($form.length === 1 && $form.validate()) {
		$.post(form.action, $form.serialize(),
			function(result) {
				if (result.success) {
					$("#lgModal").modal('hide');
		        	alertMsg(result.message,"success");
		        	userReload();
				} else {
					$form.find(".error-msg").show();
					$form.find(".error-msg").html(result.message);
				}
			}, 'json');
	}
}

$(function() {
	 
	//验证用户名         
    jQuery.validator.addMethod("userNameCheck", function (value, element) {  
        return this.optional(element) || /^[a-zA-Z]\w{6,20}$/.test(value);  
    }, "请输入6-20位字母开头的字母或数字和下划线");  
	
	$userAddForm = $("#userAddForm");
	$userAddForm.validate({
		rules: {
			nickname: {
				required: true
			},
			loginname: {
				required: true,
				userNameCheck: true
			},
			password: {
				required:true,
                minlength:6, 
                maxlength:32,
			}
		},
		messages: {
			nickname:{
				required:"昵称不能为空！"
			},
			loginname:{
				required:"登录名不能为空！",
				userNameCheck: "请输入6-20位字母开头的字母或数字和下划线"
			},
			password:{
				required:"写密码不能为空！",
				minlength:"密码至少为6个字符",
				maxlength:"密码至多为32个字符",
				
			}
		},
		submitHandler:ajaxSubmit,
		errorLabelContainer:"#userAddFormErrorMsgContainer",
		wrapper:"li",
		showErrors:function(errorMap,errorList) {
			if(errorList.length>0){
				$userAddForm.find(".error-msg").html(errorList[0].message);
			}else{
				$userAddForm.find(".error-msg").html("");
			}
		},
		onkeyup: false
	});
});
</script>